﻿/*    
    This file is part of d-mixr.

    d-mixr is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    d-mixr is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with d-mixr.  If not, see <http://www.gnu.org/licenses/>.
*/

using System;

namespace Dmixr
{
    class AudioHelpers
    {
        public static double LinearToDb(double in_value)
        {
            double val = 20* Math.Log10(in_value);

            // Prevent from returning -infinity
            if (val < -96)
            {
                return -96;
            }

            return val;
        }

        public static double DbToLinear(double in_value)
        {
            return Math.Pow(10.0, in_value / 20.0);
        }
    }
}
